<?php
// dojo helper
$this->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
// get user agent to find out if touch device is requesting the page
$userAgent = Zend_Controller_Front::getInstance()->getRequest()->HTTP_USER_AGENT;
// rename variables & fetch required data
/* @var $recipe Website_Model_Recipe */
$recipe = $this->recipe;
$photos = $recipe->getPhotos();
$videos = $recipe->getVideos();
$alternatives = $this->alternatives;
$components = $recipe->getComponents();
$gesamt = count($alternatives);
// ingredient list
foreach ( $components as /* @var $component Website_Model_Component */ $component ) {
	$ingredientList[] = $component->amount.' '.$component->unit.' '.$component->getIngredient()->name;
	$ingredientList2[] = $component->getIngredient()->name;
}
// setting meta keywords
$this->headMeta()->appendName('keywords', $recipe->name.', '.implode($ingredientList2,', ').', cocktail, rezept, cocktails, rezepte, cocktailrezepte, cocktailrezept, cocktailberater');
// setting meta description
$this->headMeta()->appendName('description', 'Das  '.$recipe->name.' Cocktailrezept besteht aus '.implode($ingredientList,', ').'. Mehr mit Beschreibung, Zubereitung, Fotos, Videos, Tags/Schlagworten, Kosten/Preisen, Kalorien und Kommentaren hier.');
// open graph type
$this->placeholder('type')->set('drink');
// rdf
$this->headLink(array('rel' => 'meta','type' => 'application/rdf+xml',
					  'title' => $recipe->name.' - RDF',
                      'href' => $this->url(array('module'=>'website','controller'=>'recipe','action'=>'get','id'=>$recipe->getUniqueName())).'?format=rdf'),'recipe',true);
// atom
$this->headLink(array('rel' => 'alternate','type' => 'application/atom+xml',
					  'title' => $recipe->name.' - Atom',
                      'href' => $this->url(array('module'=>'website','controller'=>'recipe','action'=>'get','id'=>$recipe->getUniqueName())).'?format=atom'),'recipe',true);
// rss
$this->headLink(array('rel' => 'alternate','type' => 'application/rss+xml',
					  'title' => $recipe->name.' - RSS',
                      'href' => $this->url(array('module'=>'website','controller'=>'recipe','action'=>'get','id'=>$recipe->getUniqueName())).'?format=rss'),'recipe',true);
// json
$this->headLink(array('rel' => 'alternate','type' => 'application/json',
					  'title' => $recipe->name.' - JSON',
                      'href' => $this->url(array('module'=>'website','controller'=>'recipe','action'=>'get','id'=>$recipe->getUniqueName())).'?format=json'),'recipe',true);
// xml
$this->headLink(array('rel' => 'alternate','type' => 'application/xml',
					  'title' => $recipe->name.' - XML',
                      'href' => $this->url(array('module'=>'website','controller'=>'recipe','action'=>'get','id'=>$recipe->getUniqueName())).'?format=xml'),'recipe',true);
?>
<div itemscope itemtype="http://www.data-vocabulary.org/Recipe" class="hrecipe">
<h2 class="textLeft fn" style="margin-left: 25px;" itemprop="name"><?php
print str_replace ( '\\', '', $recipe->name ) ;
if($recipe->isOriginal){
	print  ' (Originalrezept)';
}
if(!$recipe->isAlcoholic()){
	print  ' (alkoholfrei)';
}
?></h2>
<!-- class="right" -->
<div class="right clear abstand_oben">
<?php
$this->dojo()->enable()->requireModule('dojox.image.Lightbox');
$this->dojo()->addStylesheet($this->dojo()->getCdnBase().$this->dojo()->getCdnVersion().'/dojox/image/resources/Lightbox.css');
$this->headScript()->captureStart();
?>function initLightbox0() {
	var lightBox0 = new dojox.image.Lightbox({group:"photo"},dojo.byId('recipe_image'));
	lightBox0.startup();
}
dojo.addOnLoad(initLightbox0);
<?php $this->headScript()->captureEnd();?>
	<img itemprop="photo" class="photo" src="<?php
	if(isset($photos[0]) && $photos[0]->fileName) { 
		$photoUrl = $this->baseUrl() .'/img/recipes/'. $photos[ 0 ]->fileName;
	} else {
	 	$photoUrl = $this->baseUrl().'/img/glasses/'.$recipe->getGlass()->getPhoto()->originalFileName;
	}
	$this->placeholder('image')->set('http://www.cocktailberater.de'.$photoUrl);
	echo $photoUrl;
	?>" id="recipe_image" alt="<?php print str_replace ( '\\', '', $recipe->name ) ; ?>"
	title="<?php print str_replace ( '\\', '', $recipe->name ) ; ?>"
	style="margin-right: 1.6em; width: 160px; margin-top: 0.2em; margin-bottom: 20px;" />
<div id="photo_video"><?php
	if (sizeof($videos)>0) { ?>
	<a href="#videoAnchor"><img 
		src="<?php print $this->baseUrl() ;	?>/img/video.png" alt="Video"
		title="Video" height="22" width="26"
		style="margin-bottom: 0.75em; margin-right: 1em;"
		onclick="document.getElementById('video').style.display='block';" /></a><?php
	}
	$imageCounter = 0;
	if(is_array($photos)){
		foreach ( $photos as $photo ) {
			$imageCounter++;
			$this->headScript()->captureStart();
?>function initLightbox<?php echo $imageCounter; ?>() {
	var lightBox<?php echo $imageCounter; ?> = new dojox.image.Lightbox({group:"photo",href:"<?php 
	echo $this->baseUrl() .'/img/recipes/' . $photo->originalFileName ; ?>", title:"<?php 
	print str_replace ( '\\', '', $recipe->name ) ; ?>"},dojo.byId('lightbox<?php 
	echo $imageCounter; ?>'));
	lightBox<?php echo $imageCounter; ?>.startup();
}
dojo.addOnLoad(initLightbox<?php echo $imageCounter; ?>);
<?php $this->headScript()->captureEnd();?>
			<a href="<?php echo $this->baseUrl() .'/img/recipes/' . $photo->originalFileName ; ?>" 
				id="lightbox<?php echo $imageCounter; ?>" title="<?php print str_replace ( '\\', '', $recipe->name ) ; ?>"><?php
			// display photo icon for first image
			if ($imageCounter == 1) { 
			?><img src="<?php print $this->baseUrl(); ?>/img/foto.png" 
					alt="Fotos" height="21" width="28" title="Fotos"
					style="margin-right: 1em; margin-bottom: 0.7em;" /><?php 
			} // if	
			?></a>
		<?php } // foreach
	} // is array

if(!Wb_Controller_Plugin_Layout::requestFromTouchDevice()){ ?>
<a href="<?php echo $this->url(array('module'=>'website','controller'=>'recipe',
'action'=>'get','id'=>$recipe->getUniqueName()),'recipe',true); ?>?format=atom"><img src="<?php 
echo $this->baseUrl();?>/img/icons/atom_2.png" alt="Atom" style="margin-right: 1em;" /></a>
<?php }
if(!Wb_Controller_Plugin_Layout::requestFromTouchDevice()){ ?>
<span class="link" id="alternate_options_link" 
onclick="dojo.toggleClass('alternate_options_link', 'hide'); dojo.toggleClass('alternate_options', 'hide');" 
style="margin-right: 1em; vertical-align: top; text-decoration: none;">&gt;</span>
<?php } ?>
<span <?php if(!Wb_Controller_Plugin_Layout::requestFromTouchDevice()){ ?>class="hide"<?php } ?>
 id="alternate_options">
<?php if(!Wb_Controller_Plugin_Layout::requestFromTouchDevice()){ ?><a 
href="<?php echo $this->url(array('module'=>'website','controller'=>'recipe',
'action'=>'get','id'=>$recipe->getUniqueName()),'recipe',true); ?>?format=rss"><img 
src="<?php echo $this->baseUrl();?>/img/icons/rss_2.png" alt="RSS" 
style="margin-right: 1.4em;" /></a><?php } ?>
<a href="<?php echo $this->url(array('module'=>'website','controller'=>'recipe',
'action'=>'get','id'=>$recipe->getUniqueName()),'recipe',true); ?>?format=pdf"><img 
src="<?php echo $this->baseUrl(); ?>/img/icons/printer_2.png" alt="PDF Druck" 
style="margin-right: 1.4em; margin-bottom: 0.3em; margin-top: 0.6em;" /></a>
<?php if(!Wb_Controller_Plugin_Layout::requestFromTouchDevice()){ ?>
<a href="<?php echo $this->url(array('module'=>'website','controller'=>'recipe',
'action'=>'get','id'=>$recipe->getUniqueName()),'recipe',true);?>?format=xml"><img 
src="<?php echo $this->baseUrl(); ?>/img/icons/xml.png" alt="XML" 
style="margin-right: 1.4em; margin-bottom: 0.2em;" /></a>
<a href="<?php echo $this->url(array('module'=>'website','controller'=>'recipe',
'action'=>'get','id'=>$recipe->getUniqueName()),'recipe',true); ?>?format=json"><img 
src="<?php echo $this->baseUrl(); ?>/img/icons/json.png" alt="JSON" 
style="margin-bottom: 0.2em; margin-right: 1.6em; margin-top: 0.6em;" /></a>
<a href="<?php echo $this->url(array('module'=>'website','controller'=>'recipe',
'action'=>'get','id'=>$recipe->getUniqueName()),'recipe',true); ?>?format=rdf"><img 
src="<?php echo $this->baseUrl(); ?>/img/icons/rdf.png" alt="RDF" 
style="margin-left: 0.4em; margin-top: 0.5em; margin-right: 1em; margin-bottom: 0.2em; " /></a>
<?php } ?>
</span>
</div><!-- end of class="right" -->
</div>
<!-- end of class="right" -->
<div style="margin-left: 25px; margin-top: 15px; clear: none;">
<?php if($recipe->description){?><div class="attribut">Beschreibung:</div>
<div class="wert summary" itemprop="summary"><p><?php
print str_replace("\n",'</p><p>',$recipe->description);
?></p></div><?php } ?>
<div class="attribut">Zutaten:</div>
<div class="wert"><p><strong>Cocktail</strong></p><ul><?php
// dojo tooltip
$this->dojo()->enable()->requireModule('dijit.Tooltip');
$decorations = "";
$ingredients = "";
foreach ( $components as /* @var $component Website_Model_Component */ $component ) {
	$componentString = '<li itemprop="ingredient" itemscope itemtype="http://www.data-vocabulary.org/RecipeIngredient" class="ingredient">';
	$componentString .= '<span itemprop="amount"><span class="value">'.$component->amount.'</span>';
	$componentString .= ' ' ;
	$componentString .= '<span class="type">'.$component->unit.'</span></span>';
	$componentString .= ' ' ;
	
	// ingredient tooltip
	if(!Wb_Controller_Plugin_Layout::requestFromTouchDevice()){
		$this->headScript()->captureStart(); ?>
		dojo.addOnLoad(function() {
			zutat<?php print $component->getIngredient()->id ;?>Tooltip = new dijit.Tooltip({
	            connectId: ["zutat<?php print $component->getIngredient()->id ;?>"],
	            label: "<?php
	$alcoholLevel = $component->getIngredient()->getAverageAlcoholLevel();
	$calories = $component->getIngredient()->getAverageCaloriesKcal();
	$categories = $component->getIngredient()->getIngredientCategories();
	$products = $component->getIngredient()->getProducts();
	?><div style=\"text-align:left;\"><?php
	if($alcoholLevel){ ?><span class=\"pink\">Alkoholgehalt:</span> <?php print $alcoholLevel; ?> %<br /><?php }
	if($calories) { ?><span class=\"pink\">Kalorien:</span> <?php print round($calories/10); ?> kcal pro 100 ml<br /><?php } 
	if($categories) {?><span class=\"pink\">Kategorie:</span> <?php
		if(is_array($categories)){
			foreach ($categories as $category) {
				print $category->name.'<br />';
			}
		}
	}
	if($products) { ?><span class=\"pink\">Produkte:</span><?php
		if(is_array($products)){
			print '<ul style=\"font-size: 0.9em; list-style-type: circle; margin-left: 2em;\">';
			foreach ($products as $product) {
				print '<li>' . $product->name .($product->getManufacturer()->name ? ' ('.$product->getManufacturer()->name.') ' : '').' - ' .
				str_replace('.', ',', round ( $product->size, 2 )) . ' ' . $product->unit . '</li>';
			}
			print "</ul>";
		}
	}
	if(!($alcoholLevel || $calories || $categories || $products)){
		print 'Leider sind noch keine<br />Informationen zu dieser<br />Zutat vorhanden, wir<br />arbeiten daran ;)';
	}
	?></div>"
	        });
	    });
		<?php $this->headScript()->captureEnd();
	}
	// end of ingredient tooltip
	
	$componentString .= '<a id="zutat'.$component->getIngredient()->id.'" '.
							'href="'.$this->url(array('module'=>'website',
							'controller'=>'ingredient','action'=>'get',
							'id'=>$component->getIngredient()->getUniqueName()),
							'ingredient',true).'"><span itemprop="name">'.
							$component->getIngredient()->name.'</span></a>';
	if($component->getPreferredProduct()){
		$componentString .= '<ul style="margin-left: 1.9em;"><li>empfohlen <a href="'.
							$this->url(array('module'=>'website',
							'controller'=>'product','action'=>'get',
							'id'=>$component->getPreferredProduct()->getUniqueName()),
							'product',true).'">'.$component->getPreferredProduct()->name.
							'</a>'.($component->getPreferredProduct()->getManufacturer() ? 
							' von <a href="'.$this->url(array('module'=>'website',
							'controller'=>'manufacturer','action'=>'get',
							'id'=>$component->getPreferredProduct()->getManufacturer()->getUniqueName()),
							'manufacturer',true).'">'.
							$component->getPreferredProduct()->getManufacturer()->name.'</a>' : '').'</li></ul>'; 
	} 
	$componentString .= '</li>';
	
	if($component->isDecoration){
		$decorations .= $componentString;
	} else {
		$ingredients .= $componentString;
	}
} // foreach

print $ingredients;

?></ul><?php 
if($decorations) { ?>
	<p class="abstand_oben"><strong>Dekoration</strong></p>
	<ul>
	<?php print $decorations; ?>
	</ul>
<?php 
} ?>
</div>
<div class="attribut">Zubereitung:</div>
<div class="wert instructions" itemprop="instructions"><p><?php
print str_replace("\n",'</p><p>',$recipe->instruction);
?></p></div>
<?php 
if(!Wb_Controller_Plugin_Layout::requestFromTouchDevice()){
$this->headScript()->captureStart(); ?>
// sumbit the form 
var ratingFormSubmit = function(e){
    // prevent the form from actually submitting
    e.preventDefault(); 
    // submit the form in the background    
    dojo.xhrPost({
        url: "<?=$this->url(array('controller'=>'rating','action'=>'post','module'=>'website'),'rest',true)?>?format=json",
        form: "rating_form",
        handleAs: "json",
        handle: function(data,args){
            if (data.rsp["@attributes"].status == "ok"){
            	clearRatingFormError();
            	dojo.removeClass("rating_state");
            	dojo.addClass("rating_state","success");
            	dojo.byId("rating_state").innerHTML="Deine Bewertung wurde hinzugefügt.";
            }
            else if (data.rsp["@attributes"].status == "error"){
            	clearRatingFormError();
            	dojo.removeClass("rating_state");
            	dojo.addClass("rating_state","error");
            	dojo.byId("rating_state").innerHTML="Du hast schon abgestimmt!";
            }
            else {
                clearRatingFormError();
            	dojo.removeClass("rating_state");
            	dojo.addClass("rating_state","error");
            	dojo.byId("rating_state").innerHTML="Es ist ein Fehler aufgetreten. Bitte versuch es später nochmal.";
            }
        }
    });
};
dojo.addOnLoad(function(){
    var ratingForm = dojo.byId("rating_form");
    // another dojo.connect syntax: call a function directly    
    dojo.connect(ratingForm,"onsubmit",ratingFormSubmit);
});
function clearRatingFormError(){
	dojo.removeClass("rating_form")
	dojo.addClass("rating_form","hide")
}
<?php $this->headScript()->captureEnd();
} ?>
<div class="attribut">Bewertung:</div>
<div class="wert" itemprop="review" itemscope itemtype="http://www.data-vocabulary.org/Review-aggregate"><?php $durchschnitt = $recipe->getRating(); ?>
	<?php 
	// js fallback
	if($this->msg=='ok') { ?>
		<div id="rating_state" class="success">Deine Bewertung wurde hinzugefügt.</div>
	<?php }
	if($this->msg=='error') { ?>
		<div id="rating_state" class="error">Du hast schon abgestimmt!</div>
	<?php }
	// XHR / Json alternative
	else { ?>
		<div id="rating_state" class="hide">&nbsp;</div>
	<?php } ?>
	<form id="rating_form" method="post" style="margin-top: 0.3em;"
	action="<?php print $this->url(array('module'=>'website','controller'=>'rating'),'rest',true); ?>">
	<fieldset>
		<?php for($rating = 1; $rating <= 5; $rating++){
		?><button type="submit" id="rating<?php echo $rating; ?>"
			onclick="dojo.byId('rating').value='<?php echo $rating; ?>'; <?php if(!Wb_Controller_Plugin_Layout::requestFromTouchDevice()){ ?>dojo.byId('myformat').value='';<?php } ?>" 
			onmouseover="document.getElementById('img_rating<?php 
			echo $rating; ?>').src='<?php print $this->baseUrl() ; ?>/img/1_stars_pink.png';<?php 
				for($rating2=1; $rating2 <= $rating; $rating2++){ 
					echo "document.getElementById('img_rating$rating2').src='{$this->baseUrl()}/img/1_stars_pink.png';";
				}
			?>"
			onmouseout="document.getElementById('img_rating<?php 
			echo $rating; ?>').src='<?php print $this->baseUrl() ; ?>/img/<?php 
			echo ($durchschnitt >= $rating) ? '1_stars.png' : 'not_yet_rated_1.png' ; ?>';<?php 
				for($rating2=1; $rating2 <= $rating; $rating2++){ 
					if($durchschnitt >= $rating2){
						echo "document.getElementById('img_rating$rating2').src='{$this->baseUrl()}/img/1_stars.png';";
					} else {
						echo "document.getElementById('img_rating$rating2').src='{$this->baseUrl()}/img/not_yet_rated_1.png';";
					}
				}
			?>">
			<img id="img_rating<?php echo $rating; ?>" src="<?php print $this->baseUrl() ; ?>/img/<?php echo ($durchschnitt >= $rating) ? '1_stars.png' : 'not_yet_rated_1.png' ; ?>" height="18" width="18" alt="rate.." /></button><?php } ?>
		<input name="recipe" type="hidden" value="<?php echo $recipe->id; ?>" />
		<input name="rating" id="rating" type="hidden" value="" />
		<?php if(!Wb_Controller_Plugin_Layout::requestFromTouchDevice()){ ?>
			<input name="format" type="hidden" value="json" />
		<?php } ?>
		<input name="myformat" id="myformat" type="hidden" value="html" />
			<span style="vertical-align: top;">(<?php print ($recipe->ratingsCount==1 ? 
				'<span itemprop="count" style="vertical-align: top;">'.$recipe->ratingsCount.'</span> Stimme' : '<span class="count" style="vertical-align: top;">'.$recipe->ratingsCount.'</span> Stimmen');
			print ' - Ø <span itemprop="rating" style="vertical-align: top;">'.number_format ( $recipe->getRating(), 2, ',', '' ).'</span>' ; ?>)</span>
	</fieldset>
	</form></div>
<?php if($recipe->source){ ?>
<div class="attribut">Rezeptquelle:</div>
<div class="wert" itemprop="author"><?php print $recipe->source; ?></div>
<?php } ?>	
<!-- Tags -->
<div class="attribut">Schlagworte:</div>
<div class="wert"><ul id="tagList" class="no-bullet"><?php
$tags =  Website_Model_Tag::tagsByRecipeId($recipe->id,true);
foreach($tags as $tag){
	if(!Wb_Controller_Plugin_Layout::requestFromTouchDevice()){
		$this->headScript()->captureStart(); ?>
	dojo.addOnLoad(function() { 
		tag<?php print str_replace(array('-',' ','.'),array('_','__','___'),$tag->getTitle());?>Tooltip = new dijit.Tooltip({
			connectId: ["tag<?php print str_replace(array('-',' ','.'),array('_','__','___'),$tag->getTitle());?>"], 
			label: "<?php $list = Website_Model_Recipe::getRecipesByTag ( $tag->getTitle(), 5); ?>
	<h2 class=\"pink\" style=\"font-size: 1em; margin:0;\">Rezepte mit dem Tag &quot;<?php echo $tag->getTitle(); ?>&quot;:</h2><?php 
	?><ul style=\"text-align:left;\" class=\"clear no-bullet\"><?php
	foreach ($list as $key => /* @var $taggedRecipe Website_Model_Recipe */$taggedRecipe) {
		$photos = $taggedRecipe->getPhotos(1);
		?><li style=\"width: 6em; padding: 0.4em; font-size: 0.7em; clear: none; line-height: 1.5em;\" class=\"left center\"><?php 
		?><img style=\"height: 80px; margin-right: 0.5em; margin-top: 0.2em; margin-bottom: 0.2em;\" <?php 
			?>src=\"<?php print $this->baseUrl();
				if(isset($photos[0]) && $photos[0]->id){
					print '/img/recipes/'.$this->escape($photos[0]->fileName);
				} else { 
					$photos[0] = $taggedRecipe->getGlass()->getPhoto();
					print '/img/glasses/'.$this->escape($photos[0]->originalFileName);
				} ?>\" /><br /><?php echo $this->escape(str_replace('\\','',$taggedRecipe->name)) ?><?php 
		?></li><?php 
	} ?><li></li></ul>" });
	});
	<?php $this->headScript()->captureEnd();
	}
	?>
	<li class="left" style="clear: none; margin-right: 0.4em;"><a 
		href="<?php print $this->url(array('module'=>'website',
			'controller'=>'recipe','action'=>'index'),'recipes',true); 
			?>?search_type=tag&amp;search=<?php print $tag->getTitle(); ?>" 
			rel="tag" id="tag<?php print str_replace(array('-',' ','.'),
			array('_','__','___'),$tag->getTitle()); ?>"><?php 
			print $tag->name; ?></a></li>
	<?php 
}
?><li class="left" style="clear: none;"><a id="tag_prev" onclick="insertTag();" href="#tags" style="margin-top: 1em; text-decoration: underline;">Schlagwort hinzufügen</a></li></ul>
<?php
// enable dojo with custom module (readStore), parser, and comboBox
$this->dojo()->enable()
->registerModulePath('custom', '/js/custom')
->requireModule('dojo.parser')->requireModule('dojox.data.QueryReadStore')
->requireModule('dijit.form.ComboBox')->requireModule('custom.TagReadStore');
// define url for autoCompletion
$autoCompletionUrl = array('action'=>'index','controller'=>'recipe',
							'module'=>'website','format'=>'ajax','index'=>'index');
$this->headScript()->captureStart(); ?>
function initTagReadStore() {
	var tagReadStore = new custom.TagReadStore({url:"<?php echo $this->url($autoCompletionUrl,'default',true); ?>", requestMethod:"get"},dojo.byId('tagReadStore'));
	var tagSearch = new dijit.form.ComboBox({store:tagReadStore, autoComplete:false, hasDownArrow:false},dojo.byId('tagvalue'));
}
dojo.addOnLoad(initTagReadStore);
<?php $this->headScript()->captureEnd(); ?>

<div id="tagReadStore"></div>
<?php $this->headScript()->captureStart(); ?>
// configure query
djConfig.usePlainJson=true;

function initTag() {
	dojo.connect(dojo.byId("tagvalue"), 'onfocus', function(e) { // onkeypress
		/*
		// add the possibility to submit the search by pressing the ENTER key 
		if (e.keyCode == dojo.keys.ENTER) { 
			dojo.byId('tag_form').submit(); 
		}
		*/
		// hide tag_state onfocus
		dojo.removeClass("tag_state");
		dojo.addClass("tag_state","hide");
	});
}
dojo.addOnLoad(initTag);

function newSubmit(){
	// add new tag to list
	var listEntry = document.createElement("li");
	var listEntryLink = document.createElement("a");
	var listEntryText = document.createTextNode(" " + dojo.byId("tagvalue").value);
	listEntry.style.float = "left";
	listEntry.style.clear = "none";
	listEntry.style.marginRight = "0.4em";
	listEntryLink.rel = "tag";
	listEntryLink.href = "/website/recipe/index/search_type/tag/search/" + dojo.byId("tagvalue").value;
	listEntryLink.appendChild(listEntryText);
	listEntry.appendChild(listEntryLink);
	dojo.query("#tagList").forEach(function(node, index, arr){
		node.appendChild(listEntry);
	});
    // clear form and tag_state
    clearTagFormError();
    dojo.removeClass("tag_state");
    dojo.addClass("tag_state","success");
    dojo.byId("tag_state").innerHTML="Dein Tag wurde hinzugefügt.";
}

// sumbit the form 
var tagFormSubmit = function(e){
	dojo.byId('newtag').value = dojo.byId('tagvalue').value;
    // prevent the form from actually submitting
    e.preventDefault(); 
    // submit the form in the background    
    dojo.xhrPost({
        url: "<?php echo $this->url(array('controller'=>'tag','action'=>'post',
					'module'=>'website'),'rest',true)?>?format=json",
        form: "tag_form",
        handleAs: "json",
        handle: function(data,args){
            if (data.rsp["@attributes"].status == "ok"){
            	newSubmit();
            }
            else{
                clearTagFormError();
            	dojo.removeClass("tag_state");
            	dojo.addClass("tag_state","error");
            	dojo.byId("tag_state").innerHTML="Es ist ein Fehler aufgetreten. Bitte versuch es später nochmal.";
            }
        }
    });
};

// add the possibility to submit the search by pressing the ENTER key
var tagFormSubmit2 = function(e){
	dojo.byId('newtag').value = dojo.byId('tagvalue').value; 
	if (e.keyCode == dojo.keys.ENTER) { 
    	// prevent the form from actually submitting
	    e.preventDefault(); 
	    // submit the form in the background    
	    dojo.xhrPost({
	        url: "<?php echo $this->url(array('controller'=>'tag',
					'action'=>'post','module'=>'website'),'rest',true)?>?format=json",
	        form: "tag_form",
	        handleAs: "json",
	        handle: function(data,args){
	            if (data.rsp["@attributes"].status == "ok"){
	            	newSubmit();
	            }
	            else{
	                clearTagFormError();
	            	dojo.removeClass("tag_state");
	            	dojo.addClass("tag_state","error");
	            	dojo.byId("tag_state").innerHTML="Es ist ein Fehler aufgetreten. Bitte versuch es später nochmal.";
	            }
	        }
	    });
    }
};

dojo.addOnLoad(function(){
    var tagForm = dojo.byId("tag_form");
    // another dojo.connect syntax: call a function directly    
    dojo.connect(tagForm,"onsubmit",tagFormSubmit);
    dojo.connect(dojo.byId('tagvalue'), 'onkeypress', tagFormSubmit2);
});
function clearTagFormError(){
	dojo.removeClass("tag_state");
	dojo.addClass("tag_state","hide");
    dojo.byId("tagvalue").value="";
}
function insertTag(){
	dojo.addClass('tag_prev','hide');
	document.getElementById('tag_form').style.display='block';
	dijit.byId('tagvalue').focus();
}
<?php $this->headScript()->captureEnd(); ?>

<form id="tag_form" class="regular_form hide abstand_unten clear" method="post"
	action="<?php print $this->url(array('module'=>'website','controller'=>'tag'),'rest',true); ?>" style="padding-top: 1em;">
	<fieldset>
		<legend>Schlagwort hinzufügen</legend>
		<div id="tag_state" class="hide">&nbsp;</div>
		<label for="tagvalue" class="hide">Dein Schlagwort:</label>
		<!-- text input w/ autocompletion -->
		<input id="tagvalue" name="" type="text" />
		<input name="newtag" id="newtag" value="" type="hidden" />
		<input name="recipe" value="<?php print $recipe->id; ?>" type="hidden" />
		<input type="submit" class="pink" value="hinzufügen" />
	</fieldset>
</form>
</div>
<?php $this->headScript()->captureStart(); ?>
// hide all comments
function hideCommentForm() {
	dojo.byId('comment_form').style.display='none';
	dojo.byId('switchc1').style.display='block';
	dojo.byId('switchc1').innerHTML='<?php 
	$amountOfComments = count($recipe->getComments()); 
	if($amountOfComments == 4) {
		?>weiteren Kommentar anzeigen<?php 
	} elseif($amountOfComments>3) { 
		?> weitere <?php echo ($amountOfComments-3); ?> Kommentare anzeigen<?php 
	} ?>';
}
// show all comments and new comment form 
function showComments() {
	dojo.byId('commentList').style.display='block';
	dojo.byId('switchc1').innerHTML='';
	// dojo.byId('comment_form').style.display='block';
	dojo.query('ul#commentList li').removeClass('hide');
}
// display full comment form
function insertComment(){
	//showComments();
	dojo.byId('comment_form').style.display='block';
	if(dojo.byId('comment')){
		dojo.toggleClass('comment_prev','hide');
		dojo.byId('comment').focus();
	}
}
// reload captcha image 
function reloadCaptcha(){
	var xhrArgs = {
		url: "<?php echo $this->baseUrl(); ?>/website/captcha/post?format=json",
		postData: '',
		handleAs: "json",
		load: function(data) {
			dojo.byId("captcha_span").innerHTML = data.imageTag;
			dojo.byId("captchaId").value = data.id;
		},
		error: function(error) {
			alert('Beim Laden des neuen Captchas ist leider ein Fehler aufgetreten. Bitte versuch es erneut!');
		}
	}
	//Call the asynchronous xhrPost
	var deferred = dojo.xhrPost(xhrArgs);
	
}
dojo.addOnLoad(function(){
	// default hide comment form
	hideCommentForm();
	// open form and focus input
	if(location.hash=='#comment-insert'){
		insertComment();
	}
	// show comments
	if(location.hash=='#comments'){
		showComments();
	}
});
	<?php $this->headScript()->captureEnd(); ?>
<div class="attribut"><a id="comments" class="nolink">Kommentare:</a></div>
<div class="wert">
	<ul id="commentList"><?php
	if (is_array ( $this->recipe->getComments() )) {
		$currentCommentNumber = 0;
		foreach ( $this->recipe->getComments() as $comment ) {
			$currentCommentNumber++;
			?><li style="border-bottom: 1px solid rgb(170, 16, 97); margin-bottom: 0.5em;"
			<?php ($currentCommentNumber>3 ? ' class="hide"' : '') ?> itemscope itemtype="http://data-vocabulary.org/Review">
				<span class="hide" itemprop="itemreviewed"><?php 
				str_replace ( '\\', '', $recipe->name ).
				($recipe->isOriginal ? ' (original)' : '').
				(!$recipe->isAlcoholic() ? ' (alkoholfrei)' : '') ?></span>
				<p><em>
			<?php 
			if ($comment->memberId) {
				$member = new Website_Model_Member ( $comment->memberId ) ;
				?><a href="mailto:<?php print $this->escape($member->email); ?>" itemprop="reviewer">
				<?php print $this->escape(stripslashes($member->firstname)); ?> 
				<?php print $this->escape(stripslashes($member->lastname)); ?></a><?php 
			} else if($comment->name){
				if($comment->name && $comment->email){
					?><a href="mailto:<?php print $this->escape($comment->email); ?>" itemprop="reviewer">
					<?php print $this->escape(stripslashes($comment->name)); ?></a><?php
				} else {
					print $this->escape(stripslashes($comment->name));
				}
			} else { ?>
				anonym <?php 
			}
			?></em> schreibt: <span itemprop="description">
			<?php $insertDate = new Zend_Date($comment->insertDate,Zend_Date::ISO_8601);
			print ''.stripslashes(str_replace (array("\r\n", "\r", "\n",'\r\n', '\r', '\n'),
				'<br />',$this->escape($comment->comment))); ?></span> 
				<span style="color: #888888" itemprop="dtreviewed" datetime="<?php 
				print $insertDate->get(Zend_Date::DATE_SHORT,new Zend_Locale('de_DE')); ?>"><?php 
				print $insertDate->get(Zend_Date::DATETIME_SHORT,new Zend_Locale('de_DE')); ?> Uhr</span>
				</p></li><?php 
		}
	} else { ?>
		<li>keine Kommentare vorhanden</li><?php 
	}
	?></ul>
	<a id="switchc1" href="#comments" 
	class="hide clear" onclick="showComments();" 
	style="text-align: right"></a>
	<?php
	if(!$this->comment_success) { ?><textarea name="comment_prev" 
		id="comment_prev" rows="2" cols="35" 
		class="clear text left abstand_unten" onfocus="insertComment();" 
		style="font-size: 1em; margin-left: 0; margin-top: 0.4em; width: 22em; color: #888888;">Was denkst du? Dein Kommentar...</textarea><?php 
	} ?>
<form id="comment_form" class="regular_form clear"
	style="margin-top: 1em;"
	action="<?php print $this->url(array('module'=>'website','controller'=>'comment'),'rest',true); ?>#comment-insert"
	method="post">
<fieldset>
	<legend><a id="comment-insert">Kommentar hinzufügen</a></legend><?php 
	if($this->comment_error) { ?>
		<div class="error"><p>Leider ist ein Fehler beim Einfügen deines 
			Kommentares aufgetreten. Bitte überprüfe deine Eingabe!</p>
		<ul><?php 
			foreach($this->comment_error as $comment){ 
				if(is_array($comment)){ 
					foreach($comment as $subComment){ ?>
						<li><?php print $subComment; ?></li><?php
					} 
				} else { ?>
					<li><?php print $comment; ?></li><?php 
				}
			} ?>
		</ul>
		</div><?php 
	}
	if($this->comment_success) { ?>
		<p class="success"><?php print $this->comment_success; ?></p><?php 
	} 
	if(!$this->comment_success) { ?>
	<label for="name" class="clear pink left">Dein Name (optional):</label>  
	<input name="name" id="name" class="clear text left abstand_unten big<?php if($this->comment_error['name']){ print ' error'; } ?>" 
		value="<?php if($this->comment_error) { print $_POST['name']; } ?>" />
	<label for="email" class="clear pink left">Deine E-Mail-Adresse (optional):</label>  
	<input name="email" id="email" class="clear text left abstand_unten big<?php if($this->comment_error['email']){ print ' error'; } ?>" 
		value="<?php if($this->comment_error) { print $_POST['email']; } ?>" />
	<label for="comment" class="clear pink left">Dein Kommentar (reiner Text):</label>  
	<textarea name="comment" id="comment" rows="10" cols="60" 
		class="clear text left abstand_unten<?php if($this->comment_error['comment']){ print ' error'; } ?>"><?php 
		if($this->comment_error) { print $_POST['comment']; } ?></textarea>
	<label for="captcha" class="clear left" style="width: 130px; color: #444444">
		<span class="pink">Spamschutz:</span><br />
		<span class="left" id="captcha_span" style="margin-left:3px; margin-top:6px;"><?php
			$captcha = new Zend_Captcha_Image(array(
			    'name' => 'captcha',
				'font' => realpath(APPLICATION_PATH.'/../public/fonts').'/teen____.ttf',
				'imgDir' => realpath(APPLICATION_PATH.'/../public/img/captchas/'),
				'imgUrl' => $this->baseUrl().'/img/captchas/',
			    'expiration' => 300,
				'wordLen' => 5,
				'width' => 120
			));
			$captchaId = $captcha->generate();
			echo $captcha->render($this); ?></span>
	</label>
	<span class="left" style="margin-top: 26px;"><input name="captcha[input]" 
		id="captcha" value="" style="width:112px; margin-bottom: 0.7em;" 
		class="clear text left<?php if($this->comment_error['captcha']){ print ' error'; } ?>" /></span>
	<span class="left" style="margin-left: 0.5em; margin-top: 0;"><span 
		onclick="reloadCaptcha();" class="link">Spamschutz neu laden</span></span>
	<span class="left" style="margin-left: 3px;">
		Bitte die links angezeigten Zeichen angeben.</span>
	<input type="hidden" id="captchaId" name="captcha[id]" value="<?php echo $captchaId; ?>" />
	<input type="hidden" name="recipe" value="<?php echo $this->recipe->id; ?>" />
	<input type="submit" class="right pink" value="abschicken" name="submit"
	style="margin-top: 0.5em; margin-right: 3px;" /><?php 
	} ?>
</fieldset>
</form>
</div>
<?php if($gesamt) { ?>
	<div class="attribut">Rezept- alternativen:</div>
	<div class="wert full-width">
	<ul class="nolist no-bullet">
	<?php
	foreach ($alternatives as $alternative) { ?>
		<li><?php $this->cocktailPreview($alternative); ?></li>
	<?php } ?>
	</ul>
	</div>
	<?php } ?>
<div id="video" style="display: none;">
	<a id="videoAnchor"></a>
	<div class="attribut">Videoanleitung:</div>
	<div class="wert full-width"><?php
	if ($videos) {
		$i = 0 ;
		foreach ( $videos as $video ) {
			?>
		<p><strong><?php echo $video->name; ?></strong></p>
		<iframe type="text/html" width="425" 
			height="350" src="http://www.youtube.com/embed/<?php 
			print str_replace('http://www.youtube.com/v/', '', $video->url); ?>" 
			frameborder="0"></iframe>
			<?php 
			if($video->description!='') { ?>
			<p style="text-align: left; padding-top: 0.5em;">
				<em><strong>Videohinweis:</strong>
					<?php echo $video->description; ?></em>
			</p>
			<?php 
			}
		} // foreach
	}
	else { ?><p>Kein Video gefunden.</p><?php	} ?></div>
</div>
<?php $this->headScript()->captureStart(); ?>
function showStatistics() {
	dojo.toggleClass('statistic_details_link','hide');
	dojo.toggleClass('statistic_details','hide');
}
<?php $this->headScript()->captureEnd(); ?>
<div class="attribut" id="statistics">Statistiken:</div>
<div class="wert full-width"><p>
	Dieses Rezept wurde insgesamt <?php
	$totalViews = 0; 
	$htmlViews = 0;
	$printViews = 0;
	$feedViews = 0;
	$appViews = 0;
	foreach($recipe->getStatistics() as /* @var $statistic Website_Model_Statistic */ $statistic) {
		if($statistic->format == Website_Model_Statistic::FORMAT_HTML ||
			$statistic->format == Website_Model_Statistic::FORMAT_MOBILE){
			$htmlViews += $statistic->views;
		} else if($statistic->format == Website_Model_Statistic::FORMAT_RSS || 
			$statistic->format == Website_Model_Statistic::FORMAT_ATOM){
			$feedViews += $statistic->views;
		} else if($statistic->format == Website_Model_Statistic::FORMAT_PDF) {
			$printViews += $statistic->views;
		} else {
			$appViews += $statistic->views;
		} 
		$totalViews += $statistic->views;
	}
	print $totalViews; ?> mal angeschaut. <a id="statistic_details_link" 
	href="#statistics" onclick="showStatistics();">mehr Details</a></p>
	<div id="statistic_details" class="hide">
		<p class="abstand_oben">Davon waren:</p>
		<ul>
			<li style="margin-left: 2em; list-style-type: circle;"><?php 
				print ($htmlViews==1 ? '1 Aufruf' : $htmlViews.' Aufrufe'); ?> 
				über diese Webseite,</li>
			<li style="margin-left: 2em; list-style-type: circle;"><?php 
				print ($printViews==1 ? '1 Aufruf' : $printViews.' Aufrufe'); ?> 
				über die <a href="<?php echo $this->url(array(
					'module'=>'website','controller'=>'recipe',
					'action'=>'get','id'=>$recipe->getUniqueName()),'recipe',true); 
					?>?format=pdf">Druckansicht</a> dieser Seite,</li>
			<li style="margin-left: 2em; list-style-type: circle;"><?php 
				print ($feedViews==1 ? '1 Aufruf' : $feedViews.' Aufrufe'); ?> 
				über News-Reader (<a href="<?php echo $this->url(array(
					'module'=>'website','controller'=>'recipe',
					'action'=>'get','id'=>$recipe->getUniqueName()),'recipe',true); 
					?>?format=atom">Atom</a> und <a href="<?php 
				echo $this->url(array('module'=>'website','controller'=>'recipe',
					'action'=>'get','id'=>$recipe->getUniqueName()),'recipe',true); 
					?>?format=rss">RSS</a>) und</li>
			<li style="margin-left: 2em; list-style-type: circle;"><?php 
				print ($appViews==1 ? '1 Aufruf' : $appViews.' Aufrufe'); ?> 
				über andere Programme (<a href="<?php echo $this->url(array(
					'module'=>'website','controller'=>'recipe',
					'action'=>'get','id'=>$recipe->getUniqueName()),'recipe',true); 
					?>?format=xml">XML</a>, <a href="<?php 
				echo $this->url(array('module'=>'website','controller'=>'recipe',
					'action'=>'get','id'=>$recipe->getUniqueName()),'recipe',true); 
					?>?format=json">JSON</a> und <a href="<?php 
				echo $this->url(array('module'=>'website','controller'=>'recipe',
					'action'=>'get','id'=>$recipe->getUniqueName()),'recipe',true); 
					?>?format=rdf">RDF</a>).</li>
		</ul>
		<p class="abstand_oben">Eingefügt hat dieses Rezept <a class="author" 
		href="mailto:<?php print $recipe->getMember()->email; ?>"><?php 
		print $recipe->getMember()->firstname.' '.
		$recipe->getMember()->lastname; ?></a> am <span class="published">
		<span class="value-title" title="<?php $date = new Zend_Date($recipe->insertDate); print $date->getIso(); ?>"> </span><?php 
		print $date; ?></span>. Zuletzt 
		geändert wurde es am <?php $date = new Zend_Date($recipe->updateDate); 
		print $date; ?>.</p>
	</div><!-- END of id=statistic_details -->
</div><!-- END of class=wert -->
</div><!-- END of class=left -->
<div id="recipe_info" class="left">
<div class="left icon" style="left: 225px;"><img
	src="<?php
	print $this->baseUrl() ;
	?>/img/zeit.png" alt="Zeitaufwand"
	title="Zeitaufwand" height="42" width="43" /><br />
	<time itemprop="totalTime" datetime="00:0<?php print $recipe->workMin; ?>">
	<span class="duration"><span class="value-title" title="PT0H<?php print $recipe->workMin; ?>M"> </span><?php print $recipe->workMin; ?> min</span></time>
	<span class="hide yield" itemprop="yield">1 Glas</span></div>
<div class="left icon" style="left: 140px;"><img
	src="<?php
	print $this->baseUrl() ;
	?>/img/<?php
	if ($recipe->difficulty == Website_Model_Recipe::BEGINNER) {
		print "difficulty/beginner.png" ;
		$difficultyMessage = 'Anfänger';
	}
	else if ($recipe->difficulty == Website_Model_Recipe::ADVANCED) {
		print "difficulty/advanced.png" ;
		$difficultyMessage = 'Fortgeschritten';
	}
	else if ($recipe->difficulty == Website_Model_Recipe::PROFI) {
		print "difficulty/professional.png" ;
		$difficultyMessage = 'Profi';
	} else {
		// TODO: Bild erstellen, welches ausdrückt, dass es keine Information dazu gibt...
		print "difficulty/unknown.png" ;
		$difficultyMessage = 'nicht eingestuft';
	}
	?>" 
	alt="Schwierigkeitsgrad <?php
	print $difficultyMessage;
	?>"
	title="Schwierigkeitsgrad <?php
	print $difficultyMessage;
	?>" /><br />
	<?php
	print $difficultyMessage
	;
	?></div>
<div class="left icon" style="left: -20px;"><img
	src="<?php
	echo $this->baseUrl() .'/img/glasses/'. $recipe->getGlass()->getPhoto()->fileName ;
	?>"
	alt="Glas <?php
	print $recipe->getGlass()->name ;
	?>"
	title="Glas <?php
	print $recipe->getGlass()->name ;
	?>" /><br />
	<?php
	print $recipe->getGlass()->name ;
	?></div>
	<?php
	$caloriesStyle = '';
	if(!Wb_Controller_Plugin_Layout::requestFromTouchDevice()){
		$this->headScript()->captureStart(); ?>
		dojo.addOnLoad(function() {
			caloriesInfoTooltip = new dijit.Tooltip({
				connectId: ["caloriesInfo"],
				label: "<?php
					$calories = $recipe->getCaloriesKcal();
					$caloriesComplete = true;
					if(is_array($components)){
						foreach ($components as $component) {
							if($component->getCaloriesKcal() === NULL && $component->getCaloriesKcal() !== 0){
								$caloriesComplete = false;
							}
							$caloriesList .= '<li>'.$component->amount.' '.
											 $component->unit.' '.
											 $component->getIngredient()->name . ': ' .
								(($component->getCaloriesKcal() === NULL && $component->getCaloriesKcal() !== 0) ? 
									' k.a. ' : 
									round($component->getCaloriesKcal()).' kcal'  ) . '</li>';
						}
					}
					?><div style=\"text-align:left;\"><?php 
					?><span class=\"pink\">Gesamtkalorien:</span> <?php
					if(!$caloriesComplete){
						print 'über ';
					}
					print '<span>'.$calories.'</span>'; ?> kcal<br /><?php
					?><span class=\"pink\">Kalorienaufteilung:</span><ul style=\"font-size: 0.9em; list-style-type: circle; margin-left: 2em;\"><?php
						print $caloriesList;
					?></ul></div>"
	        });
	    });<?php
	    $this->headScript()->captureEnd();
	    $caloriesStyle = ' style="text-decoration: underline; text-underline-style: dotted; cursor: pointer; color: rgb(84, 97, 110);"';
	}
	?>
<div class="left icon" style="left: 300px;" id="caloriesInfo"><img
	src="<?php print $this->baseUrl(); ?>/img/calories.png" alt="Kalorien" height="48" width="33"
	title="Kalorien" /><br />
	<span<?php print $caloriesStyle;?>><?php
	if(!$caloriesComplete){
		print 'über ';
	} ?><span style="white-space: nowrap" itemprop="calories" class="nutrition">
			<span class="value"><?php print $recipe->getCaloriesKcal(); ?></span> 
         	<span class="type">kcal</span>
    	</span>
	</span>
</div>
<div class="left icon" style="left: 390px;"><img  height="42" width="34"
	src="<?php
	print $this->baseUrl() ;
	?>/img/prozent.png" alt="Alkoholgehalt"
	title="Alkoholgehalt" /><br />
	<?php
	print round($recipe->getAlcoholLevel());
	?> % Alkohol</div>
	<?php 
	$priceStyle = '';
	if(!Wb_Controller_Plugin_Layout::requestFromTouchDevice()){
		$this->headScript()->captureStart(); ?>
		dojo.addOnLoad(function() {
			priceInfoTooltip = new dijit.Tooltip({
				connectId: ["priceInfo"],
				label: "<?php // must be all in one line -> js attribute	
					$price = number_format($recipe->getAveragePrice(),2,',','.');
					$components = $recipe->getComponents();
					$priceComplete = true;
					if(is_array($components)){
						foreach ($components as $component) {
							if(!$component->getAveragePrice()){
								$priceComplete = false;
							}
							$priceList .= '<li>'.$component->amount.' '.$component->unit.' '.$component->getIngredient()->name . ': ' .
								($component->getAveragePrice() != null ? number_format($component->getAveragePrice(),2,',','.').' €' : ' k.a. ').'</li>';
						}
					}
					?><div style=\"text-align:left;\"><?php 
					?><span class=\"pink\">Gesamtpreis:</span> <?php
					if(!$priceComplete){
						print 'über ';
					}
					print $price; ?> €<br /><?php
					?><span class=\"pink\">Preisaufteilung:</span><ul <?php
					?>style=\"font-size: 0.9em; list-style-type: circle; margin-left: 2em;\"><?php
						print $priceList;
					?></ul></div>"
	        });
	    });<?php
	    $this->headScript()->captureEnd();
	    $priceStyle = ' style="text-decoration: underline; text-underline-style: dotted; cursor: pointer; color: rgb(84, 97, 110);"';
	}
	?>
<?php if($recipe->getAveragePrice() > 0) {?>
<div class="left icon" style="left: 480px;" id="priceInfo"><img  height="42" width="34"
	src="<?php print $this->baseUrl(); ?>/img/icons/money.png" alt="Preis / Kosten"
	title="Preis / Kosten" /><br /><span<?php print $priceStyle; ?>>
	<?php
	if(!$priceComplete){
		print 'über ';
	}
	print number_format($recipe->getAveragePrice(),2,',','.');
	?> €</span></div>
<?php } ?>
<div class="left icon" style="left: 60px;"><img  height="47" width="25"
	src="<?php
	print $this->baseUrl() ;
	?>/img/volumen.png" alt="Volumen"
	title="Volumen" /><br />
	<?php
	print $recipe->getVolumeCl() ;
	?> cl</div>
</div>
</div>